const { merge } = require("webpack-merge")
const HtmlWebpackPlugin = require("html-webpack-plugin")
const common = require("./webpack.common")
const path = require("path")
const glob = require("glob")
const webpack = require("webpack")
const { CleanWebpackPlugin } = require("clean-webpack-plugin")

let htmlPlugins = []
const getEntry = function (rule) {
    const files = glob.sync(rule)
    let entry = new Object()
    files.forEach(item => {
        let key = "pages/" + item.split("/").splice(2).join("/")
        entry[key] = item
        let htmlKey = key.split(".").shift()
        htmlPlugins.push(new HtmlWebpackPlugin({
            template: "./template.html",
            filename: htmlKey + ".html",
            chunks: [key]
        }))
    })
    return entry
}

module.exports = merge(common, {
    entry: "./src/server",
    target: "node",
    output: {
        filename: "index.js",
        path: path.resolve(__dirname, "build/server"),
        publicPath: "/"
    },
    plugins: [
        new CleanWebpackPlugin(),
        new webpack.ProvidePlugin({
            "home": [path.resolve(__dirname, "/src/home/index.vue"), "default"],
            "test": [path.resolve(__dirname, "/src/test.js"), , "default"]
        }),
    ],
    resolve: {
        extensions: [".js", ".vue"]
    }
})